//
//  FineCell.m
//  HappyTrip
//
//  Created by dlios on 15-3-24.
//  Copyright (c) 2015年 lanou3g.com 蓝鸥科技. All rights reserved.
//

#import "FineCell.h"

@implementation FineCell

- (void)dealloc
{
    [_goodLabel1 release];
    [_goodLabel2 release];
    [_goodLabel3 release];
    [_goodLabel4 release];
    [_titleLabel release];
    [_titleImage release];
    [_labelImage1 release];
    [_labelImage2 release];
    [_labelImage3 release];
    [_labelImage4 release];
    [_recommend release];
    [super dealloc];
}

-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        self.titleLabel = [[UILabel alloc] init];
        [self.contentView addSubview:self.titleLabel];
        self.titleImage = [[UIImageView alloc] init];
        [self.titleLabel addSubview:self.titleImage];
        [_titleImage release];
        [_titleLabel release];
        
        self.goodLabel1 = [[UILabel alloc] init];
        self.goodLabel1.layer.cornerRadius = 5;
        self.goodLabel1.clipsToBounds = YES;
        [self.contentView addSubview:self.goodLabel1];
        self.labelImage1 = [[UIImageView alloc] init];
//        self.titleImageView.contentMode = UIViewContentModeScaleAspectFill;
//        self.titleImageView.clipsToBounds = YES;
        self.labelImage1.contentMode = UIViewContentModeScaleAspectFill;
//        self.labelImage1.clipsToBounds = YES;
        [self.goodLabel1 addSubview:self.labelImage1];
        [_labelImage1 release];
        [_goodLabel1 release];
        
        self.goodLabel2 = [[UILabel alloc] init];
        self.goodLabel2.layer.cornerRadius = 5;
        self.goodLabel2.clipsToBounds = YES;
        [self.contentView addSubview:self.goodLabel2];
        self.labelImage2 = [[UIImageView alloc] init];
        self.labelImage2.contentMode = UIViewContentModeScaleAspectFill;
//        self.labelImage2.clipsToBounds = YES;
        [self.goodLabel2 addSubview:self.labelImage2];
        [_labelImage2 release];
        [_goodLabel2 release];
        
        self.goodLabel3 = [[UILabel alloc] init];
        self.goodLabel3.layer.cornerRadius = 5;
        self.goodLabel3.clipsToBounds = YES;
        [self.contentView addSubview:self.goodLabel3];
        self.labelImage3 = [[UIImageView alloc] init];
        self.labelImage3.contentMode = UIViewContentModeScaleAspectFill;
        [self.goodLabel3 addSubview:self.labelImage3];
        [_labelImage3 release];
        [_goodLabel3 release];
        
        self.goodLabel4 = [[UILabel alloc] init];
        self.goodLabel4.layer.cornerRadius = 5;
        self.goodLabel4.clipsToBounds = YES;
        [self.contentView addSubview:self.goodLabel4];
        self.labelImage4 = [[UIImageView alloc] init];
        self.labelImage4.contentMode = UIViewContentModeScaleAspectFill;
        [self.goodLabel4 addSubview:self.labelImage4];
        [_labelImage4 release];
        [_goodLabel4 release];
    }
    return self;
}

-(void)layoutSubviews
{
    [super layoutSubviews];
    CGFloat width = self.contentView.bounds.size.width / 2;
    CGFloat heigth = (self.contentView.bounds.size.height - 30) / 2;

    
    self.titleLabel.frame = CGRectMake(10, 0, width * 2 - 20, 30);
    self.titleLabel.text = [NSString stringWithFormat:@" %@", self.recommend.title];
    self.titleImage.frame = CGRectMake(0, 5, 3, 20);
    self.titleImage.image = [UIImage imageNamed:@"ticket_@2x.png"];

    self.goodLabel1.frame = CGRectMake(10, 35, width - 15, heigth - 7.5);
    self.labelImage1.frame = self.goodLabel1.bounds;
    NSString *str1 = [[self.recommend.data objectAtIndex:0] objectForKey:@"photo"];
    NSURL *url = [NSURL URLWithString:str1];
    [self.labelImage1 setImageWithURL:url placeholderImage:[UIImage imageNamed:@"placeholder.png"]];
//    [self.goodLabel1 addSubview:[self getView:0]];
    
    self.goodLabel2.frame = CGRectMake(width + 5, 35, width - 15, heigth - 7.5);
    self.labelImage2.frame = self.goodLabel1.bounds;
    NSString *str2 = [[self.recommend.data objectAtIndex:1] objectForKey:@"photo"];
    NSURL *url2 = [NSURL URLWithString:str2];
    [self.labelImage2 setImageWithURL:url2 placeholderImage:[UIImage imageNamed:@"placeholder.png"]];
//    [self.goodLabel2 addSubview:[self getView:1]];

    self.goodLabel3.frame = CGRectMake(10, heigth + 37.5, width - 15, heigth - 7.55);
    self.labelImage3.frame = self.goodLabel1.bounds;
    NSString *str3 = [[self.recommend.data objectAtIndex:2] objectForKey:@"photo"];
    NSURL *url3 = [NSURL URLWithString:str3];
    [self.labelImage3 setImageWithURL:url3 placeholderImage:[UIImage imageNamed:@"placeholder.png"]];
//    [self.goodLabel3 addSubview:[self getView:2]];
    
    self.goodLabel4.frame = CGRectMake(width + 5, heigth + 37.5, width - 15, heigth - 7.5);
    self.labelImage4.frame = self.goodLabel1.bounds;
    NSString *str4 = [[self.recommend.data objectAtIndex:3] objectForKey:@"photo"];
    NSURL *url4 = [NSURL URLWithString:str4];
    [self.labelImage4 setImageWithURL:url4 placeholderImage:[UIImage imageNamed:@"placeholder.png"]];
//    [self.goodLabel4 addSubview:[self getView:3]];

}
//- (UIImageView *)getView:(NSInteger)index
//{
//    UIImageView *imageView = [[UIImageView alloc] initWithFrame:self.goodLabel1.bounds];
//    NSString *str = [[self.recommend.data objectAtIndex:index] objectForKey:@"photo"];
//    NSURL *url = [NSURL URLWithString:str];
//    [imageView setImageWithURL:url];
//    
//    return [imageView autorelease];
//}


- (void)awakeFromNib {
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
